
import os
CUR_DIR = os.path.dirname(os.path.abspath(__file__)) + "/"
from utils import utils
class template_ts:
    def __init__(self,sheet_model):

        self.sheet_model = sheet_model

    def build(self):
        
        params = ""

        for i in range(0,len(self.sheet_model.value_types)):
            value_type = self.sheet_model.value_types[i]
            value_name = self.sheet_model.value_names[i]
            default_value = self.get_default_value(value_type)
            params = params +  f"    public {value_name}:{value_type} = {default_value};\n"
        sheet_name = self.sheet_model.sheet_name
        temp_str = utils.getStringFromFile(CUR_DIR + "model.ts")
        temp_str = temp_str.replace("Test",sheet_name)
        temp_str = temp_str.replace("//param1",params)

        
        param2 = f"export const Cfg{sheet_name}s:{{[key:{self.sheet_model.key_type}]:Cfg{sheet_name}}} = ConfigObjects['{sheet_name}'];"
        temp_str = temp_str.replace("//param2",param2)
        self.output_text = temp_str
        return self.output_text
    def get_default_value(self,value_type):
        if value_type == "string":
            return "''"
        elif value_type == "number":
            return 0
        
    def save(self,dir):
        target_filename = f"Cfg{self.sheet_model.sheet_name}.ts"
        target_file_path = dir + "/" + target_filename

        utils.writeFile(target_file_path,self.output_text)